import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;

public class appletTest extends Applet implements ActionListener {

	JLabel court[];
	JLabel courtStatus[];
	String courtAvailability;
	JTextField inputCourts;
	JTextField inputCourse;
	JFormattedTextField inputDateStart;
	JFormattedTextField inputDateEnd;
	JFormattedTextField inputTimeStart;
	JFormattedTextField inputTimeEnd;
	JRadioButton searchRadioButtonDateCourse;
	JRadioButton searchRadioButtonDateCourt;
	JRadioButton searchRadioButtonCourt;
	JRadioButton searchRadioButtonCourse;
	
    protected static final String textFieldString = "JTextField";
	

	public appletTest() {

		

	}

	public void init() {
		
		setSize(500,500);
		court = new JLabel[15];
		courtStatus = new JLabel[15];
		inputCourts = new JTextField(5);
		inputCourse = new JTextField(5);
		inputDateStart = new JFormattedTextField(); //java.util.Calendar.getInstance().getTime()
		inputDateEnd = new JFormattedTextField();
		inputTimeStart = new JFormattedTextField();
		inputTimeEnd = new JFormattedTextField(); 
		searchRadioButtonDateCourse = new JRadioButton();
		searchRadioButtonDateCourt = new JRadioButton();
		searchRadioButtonCourt = new JRadioButton();
		searchRadioButtonCourse = new JRadioButton();
		//setLayout(new GridLayout(2, 1));
		
		
		//----------------Search By Pane------------------------------
		JPanel searchByPane = new JPanel();
		searchByPane.setLayout(new GridLayout(4,2));
		searchByPane.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder("Search By"),
                BorderFactory.createEmptyBorder(5,5,5,5)));
		
		
		ButtonGroup group = new ButtonGroup();
		group.add(searchRadioButtonDateCourse);
		group.add(searchRadioButtonDateCourt);
		group.add(searchRadioButtonCourt);
		group.add(searchRadioButtonCourse);
		
		//Register a listener for the radio buttons
		searchRadioButtonDateCourt.addActionListener(this);
		searchRadioButtonDateCourse.addActionListener(this);
		searchRadioButtonCourt.addActionListener(this);
		searchRadioButtonCourse.addActionListener(this);
		
		JLabel searchDateCourse = new JLabel("Date for course: ");
		JLabel searchDateCourt = new JLabel("Date for court: ");
		JLabel searchCourse = new JLabel("Course: ");
		JLabel searchCourt = new JLabel("Court: ");
		
		searchByPane.add(searchDateCourse);
		searchByPane.add(searchRadioButtonDateCourse);
		searchByPane.add(searchDateCourt);
		searchByPane.add(searchRadioButtonDateCourt);
		searchByPane.add(searchCourt);
		searchByPane.add(searchRadioButtonCourt);
		searchByPane.add(searchCourse);
		searchByPane.add(searchRadioButtonCourse);
		add(searchByPane);		
		
		// -----------------End of Search By Pane -------------------------
		
		
		// ---------------------- Search Input Pane ------------------------
		JPanel searchPane = new JPanel();
		searchPane.setLayout(new GridLayout(4,1));
		searchPane.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder("Search Input"),
                BorderFactory.createEmptyBorder(5,5,5,5)));
		
		JLabel inputCourtLabel = new JLabel("Court: ");
		searchPane.add(inputCourtLabel);
		searchPane.add(inputCourts);
		
		JLabel inputCourseLabel = new JLabel("Course: ");
		searchPane.add(inputCourseLabel);
		searchPane.add(inputCourse);
		
		
		JPanel dateBoxes = new JPanel();
		dateBoxes.setLayout(new GridLayout(1,2));
		JLabel inputDateLabel = new JLabel("Date: ");
		dateBoxes.add(inputDateStart);
		dateBoxes.add(inputDateEnd);
		searchPane.add(inputDateLabel);
		searchPane.add(dateBoxes);
		
		JPanel timeBoxes = new JPanel();
		timeBoxes.setLayout(new GridLayout(1,2));
		JLabel inputTimeLabel = new JLabel("Time: ");
		timeBoxes.add(inputTimeStart);
		timeBoxes.add(inputTimeEnd);
		searchPane.add(inputTimeLabel);
		searchPane.add(timeBoxes);

		
		add(searchPane);
		// ---------------- End Search Input Pane ------------------------
	
		
		
		
		// Sample Output
		ArrayList<ArrayList<String>> test = new ArrayList<ArrayList<String>>();
		for(int j = 0; j < 4; j++) {
			ArrayList<String> value = new ArrayList<String>();
			value.add("First");
			value.add("Second");
			value.add("Thirds");
			value.add("Fourth");
			test.add(j, value);
			
		}
		TableModel tm = new TableModel(test);
		
		
		// ------------------- Output Pane---------------------------------------
		JPanel outputPane = new JPanel();
		outputPane.setLayout(new GridLayout(tm.getRowCount()+1, tm.getColumnCount()));
		outputPane.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder("Output"),
                BorderFactory.createEmptyBorder(5,5,5,5)));
		
		ArrayList<ArrayList<JLabel>> records = new ArrayList<ArrayList<JLabel>>();
		
		for (int i =0; i < tm.getColumnCount(); i++) {
			JLabel out1 = new JLabel(tm.getColumns().get(i));
			outputPane.add(out1);
		}
		
		
		for (int i = 0; i < tm.getRowCount(); i++) {
			for (int j = 0; j < tm.getColumnCount(); j++) {
				
				JLabel out2 = new JLabel(tm.getValueAt(i,j));
				outputPane.add(out2);
			}
			
		}
		add(outputPane);
		// -------------------- End Output Pane --------------------------------
		
		
		
		
		JFormattedTextField ftf = new JFormattedTextField(java.util.Calendar.getInstance().getTime());
		add(ftf);
		
		
	}

	
	public void actionPerformed(ActionEvent ae) {
		
	}

}
